﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FacebookWrapper.ObjectModel;

namespace B12_Ex01_Guy_066473471_Erez_021616735.userInterfaceForWindowsInWinForm
{
   
    interface IPostedItem
    {
         FacebookObjectCollection<Comment> Comments { get; }
         DateTime? CreatedTime { get; }
         User From { get; }
         FacebookObjectCollection<User> LikedBy { get; }

         Comment Comment(string i_Comment);
         bool Like();
         bool Unlike();

         string ToString();
    }


    class FactoryAdapterPostItem
    {
        public abstract class AdapterPostedItem
        {
            /// <summary>
            ///  The base class of the concrete polymorphic classes
            ///  exposes a static public factory method
            /// </summary>
            /// <returns>a reference to the newly created concrete instance</returns>
            public static IPostedItem CreateAdapterPostItem(PostedItem i_Choice)
            {
                /// NOTE:
                /// This code could be easily replaced with
                /// a code that reads a configuration file
                /// which holds inforamtion (that can be updated/modified)
                /// regarding which instance to create in respect to i_Choice

                if (i_Choice is Checkin)
                {
                    return new AdapterCheckin() { checkin = i_Choice as Checkin };
                }
                else if (i_Choice is Status)
                {
                    return new AdpterStatus() { status = i_Choice as Status };
                }
                else
                {
                    return null;
                }
            }

            public abstract void Draw();
        }

        public class AdapterCheckin : IPostedItem
        {

            public Checkin checkin { get; set; }

            public FacebookObjectCollection<Comment> Comments
            {
                get { return checkin.Comments; }
            }

            public DateTime? CreatedTime
            {
                get { return checkin.CreatedTime; }
            }

            public User From
            {
                get { return checkin.From; }
            }

            public FacebookObjectCollection<User> LikedBy
            {
                get { return checkin.LikedBy; }
            }

            public Comment Comment(string i_Comment)
            {
                return checkin.Comment(i_Comment);
            }

            public bool Like()
            {
                return checkin.Like();
            }

            public bool Unlike()
            {
                return checkin.Unlike();
            }

            public override string ToString()
            {
                //return String.Format(" {0},on {1}", checkin.Place,checkin.CreatedTime.ToString());
                return String.Format(" {0}, on {1}", checkin.Place.Name, checkin.CreatedTime.ToString());
            }
        }

        public class AdpterStatus : IPostedItem
        {
            public Status status { get; set; }

            public FacebookObjectCollection<Comment> Comments
            {
                get { return status.Comments; }
            }

            public DateTime? CreatedTime
            {
                get { return status.CreatedTime; }
            }

            public User From
            {
                get { return status.From; }
            }

            public FacebookObjectCollection<User> LikedBy
            {
                get { return status.LikedBy; }
            }

            public Comment Comment(string i_Comment)
            {
                return status.Comment(i_Comment);
            }

            public bool Like()
            {
                return status.Like();
            }

            public bool Unlike()
            {
                return status.Unlike();
            }

            public override string ToString()
            {
                //return String.Format(" {0},on {1}", checkin.Place,checkin.CreatedTime.ToString());
                return String.Format(" {0},People Like this: {1} ", status.Message, status.LikedBy.Count());
            }
        }
    }
}
